package LeetCode;

import sun.security.util.ArrayUtil;

import java.util.Arrays;
import java.util.Stack;

/**
 * @Author: Dijah
 * @Date: 2023/2/6 16:56
 * @Desc: 下一个更大的元素
 *  https://leetcode.cn/problems/next-greater-element-ii/
 */
public class code503_nextGreaterElements {
    //使用单调栈
    public static int [] nextGreaterElements(int[] nums){
        int n = nums.length;
        int [] res = new int[n];
        Stack<Integer> stack = new Stack<>();
        for(int i = nums.length * 2 -1; i >= 0; i--){
            while (!stack.isEmpty() && nums[i%n] >= stack.peek()){
                stack.pop();
            }
            res[i%n] = stack.isEmpty() ? -1 : stack.peek();
            stack.push(nums[i%n]);
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(2%3);
    }
}
